﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CostaRicaPureTravel.Controller;
using CostaRicaPureTravel.UserControls;
using CostaRicaPureTravelUtils.EmailConfiguration;

namespace CostaRicaPureTravel
{
    public partial class contact_us : System.Web.UI.Page
    {
        private EmailController controller;

        protected void Page_Init(object sender, EventArgs e) 
        {
            controller = new EmailController(this.Context);
            AjaxPopUp.EventDelegate = btnOkEvent;
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSendEmail_Click(object sender, EventArgs e)
        {
            try
            {
                if (Page.IsValid)
                {
                    String name = String.Format("{0} {1}", txtFirstName.Text, txtLastName.Text);
                    String body = EmailContent.getEmailTemplate(EmailContent.EmailType.CONTACT, name, txtPhone.Text, dropWhoAreYou.SelectedItem.Text, dropAbleArrage.SelectedItem.Text, txtMessage.Text);
                    controller.Send(txtEmailAddress.Text, name, EmailContent.SUBJECT_CONTACT, body, true);
                }
                else 
                {
                    return;
                }
            }
            catch (Exception ex) {
                AjaxPopUp.MessageType = AjaxBasedPopUpControl.PopupMessageType.Error;
                AjaxPopUp.Message = "CONTACT_GENERAL_ERROR";
            }
            AjaxPopUp.ShowPopupMessage();
        }


        protected void btnOkEvent(object sende, EventArgs e) {
            Response.Redirect(ResolveUrl("contact_us.aspx"));
        }
    }
}